
#include "defines.h"
#include "video/Bone.h"

namespace KEngine
{

Bone::Bone()
: mParentName("")
{
	D3DXMatrixIdentity(&mInitTM);
	D3DXMatrixIdentity(&mInverseInitTM);
	D3DXMatrixIdentity(&mTransform);
}

Bone::~Bone()
{

}

void Bone::update()
{
	if (_parent)
		mTransform *= static_cast<Bone*>(_parent)->mTransform;
	else
	{
		D3DXMATRIX mat;
		D3DXMatrixIdentity(&mat);
		mTransform *= mat;
	}

	Bone* child = 0;
	for (ChildNodeIterator i = _children.begin(); i != _children.end(); ++i)
		static_cast<Bone*>(i->second)->update();

	// set mTransform as offset transform to its original TM, avoid that the
	// application has to calculate it every time the bone is used.
	mTransform = mInverseInitTM * mTransform;
}

}